package com.leetcode.demo3Solution.JianOffer;

import javax.lang.model.element.VariableElement;
import java.util.Arrays;

public class offer03 {
    public static void main(String[] args) {
       int[] n={2, 7, 1, 0, 5, 5, 3,8};
       // int a=Solution(n);
        Solution1 su=new Solution1();
        int b= su.findRepeatNumber(n);
        System.out.println(b);
    }

    public static int  Solution(int[] nums) {
            Arrays.sort(nums);
            int str=nums[0];
            int start;
            for (int i=1;i<nums.length;i++){
                start=nums[i];
                if(str==start){
                    return  start;
                }else {
                    str=nums[i];
                }
            }
            return  0;
    }
}

class Solution1 {
    public int findRepeatNumber(int[] nums) {
        int len=nums.length;
        int[] arr=new int[len+1];
        for(int a : nums){
            if(a!=0){
                arr[a-1]+=1;
            }else {
                arr[arr.length-1]+=1;
            }
        }
        for(int i=0;i<arr.length;i++){
            if(arr[i]>1) return i+1;
        }
        return -1;
    }
}




